package daily;

import java.util.Arrays;
import java.util.Comparator;

/**
 * @author MtRider
 * @version 1.0
 * @description  最大数
 * @GiteeAndGithub MtRider
 * @date 2022/5/1 12:08
 */
public class demo22 {
    public static void main(String[] args) {
        int [] nums={3,30,34,5,9};
        System.out.println(largestNumber(nums));

    }

    public static String largestNumber(int[] nums) {
        if(nums.length ==0){
            return "";
        }
        String [] str=new String[nums.length];
        for (int i = 0; i < nums.length; i++) {
            str[i]=String.valueOf(nums[i]);
        }

        Arrays.sort(str, new Comparator<String>() {
            @Override
            public int compare(String o1, String o2) {
                return (o2+o1).compareTo(o1+o2);
            }
        });
        StringBuilder sb = new StringBuilder();
        for (String s : str) {
            sb.append(s);
        }

        String result = sb.toString();
        if(result.charAt(0) == '0'){
            return "0";
        }
        return result;

    }
}
